var $;
layui.use(['form','layer','jquery'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage;
		$ = layui.jquery;

	var selectPid = $('[name="id"]').attr('data-id');
	$('[name="pid"]').val([selectPid]);
	form.render('select');

	form.on("submit(editRule)",function(data){
		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
		$.ajax({
			url: '/editRule',
			type: 'POST',
			dataType: 'json',
			timeout: 3000,
			data: data.field,
			complete: function(){
				top.layer.close(index);
			},
			error: function(){
				layer.alert('参数错误', {icon: 2}, function(index){
					layer.close(index);
				});
			},
			success: function(res){
				if (res.status != 0) {
					top.layer.close(index);
					layer.alert(res.msg, {icon: 2}, function (index) {
						layer.close(index);
					})
					return false;
				}
				top.layer.msg("更新成功！");
				layer.closeAll("iframe");
				//刷新父页面
				parent.location.reload();
			}
		});
 		return false;
 	})
	
})


